fix: 大盘分析的历史执行记录丢失 (#1306) - #1307
Conversation
🤖 自动审查报告
📁 修改的文件
🧠 AI 代码审查意见审查结论Ready to Merge 结构化审查结果
必改项 (0 条)当前 PR 不存在阻碍合入的必改项。 建议项 (2 条)
|
There was a problem hiding this comment.
Pull request overview
Persists market review (大盘复盘) executions into the existing analysis_history table so that Web/API history can list and re-open previously generated reviews without re-running the pipeline. Closes #1306.
Changes:
src/core/market_review.pyadds aquery_idparameter and a_persist_market_review_historyhelper that saves the review report viaDatabaseManager.save_analysis_historywith a newreport_type="market_review".api/v1/endpoints/analysis.pypre-generates atask_id, forwards it to the backgroundrun_market_reviewasquery_id, andget_analysis_statusnow returnsmarket_review_reportreconstructed from DB rows withreport_type == "market_review".src/services/task_queue.pyaccepts an externally providedtask_idinsubmit_background_task(with duplicate-ID guard);src/services/history_service.pyreturns the persisted Markdown directly for market review rows; tests added/updated.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/core/market_review.py | Adds query_id param and _persist_market_review_history helper writing into AnalysisHistory. |
| api/v1/endpoints/analysis.py | Pre-allocates task_id, forwards as query_id, returns market review report from DB lookup. |
| src/services/task_queue.py | submit_background_task accepts external task_id with duplicate check. |
| src/services/history_service.py | get_markdown_report short-circuits for market_review records. |
| docs/CHANGELOG.md | Adds Unreleased flat fix entry for market review history persistence. |
| tests/test_market_review.py | Patches new persistence helper and adds DB persistence test. |
| tests/test_analysis_history.py | Asserts persisted market review report returned verbatim. |
| tests/test_analysis_api_contract.py | Asserts /status returns market_review_report from DB. |
2d72848 to
b750cf2
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2d72848111
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| record_id=record_id | ||
| ) | ||
|
|
||
| if getattr(record, "report_type", None) == "market_review": |
There was a problem hiding this comment.
Return market review content from history detail
When a persisted market review row appears in the Web history list, clicking it follows stockPoolStore.selectHistoryItem -> historyApi.getDetail -> /api/v1/history/{id}, not the Markdown drawer endpoint. This branch only special-cases get_markdown_report, so the initial history view still renders the new market_review row as a stock-style report with just the short summary/empty sections; users must discover the separate full-report drawer to see the recap, which leaves the advertised direct Web history viewing path incomplete. Please also special-case the history detail/client path to surface the saved recap content.
Useful? React with 👍 / 👎.
ZhuLinsen
left a comment
There was a problem hiding this comment.
评审结论
- 必要性:通过 + 修复 #1306 中大盘复盘结果不入历史、导致 Web/API 侧重复触发的问题,业务价值明确。
- 是否有对应 issue:有,Closes #1306
- PR 类型:fix + 复用现有分析历史机制持久化并查询大盘复盘结果。
- description 完整性:不完整 + 背景、范围、验证、风险和回滚已给出,但文档同步 checklist 未闭环,且未说明中英文专题文档是否需要同步;结构化提示中的 LLM/provider 风险经 diff 复核未见实际运行时模型、provider、Base URL 或配置清理逻辑变更。
- 是否可直接合入:不可 + 需先补齐 Web 历史查看链路对
market_review的实际展示/回归验证,并按 AGENTS.md 补齐用户可见 API/Web 行为文档。
主要问题
- [Correctness blocker]
src/core/market_review.py、src/services/history_service.py、api/v1/endpoints/history.py、apps/dsa-web/src/stores/stockPoolStore.ts:本 PR 已把完整复盘 Markdown 存入历史,并让/history/{id}/markdown可返回正文,但 Web 历史列表点击仍走selectHistoryItem -> historyApi.getDetail -> GET /api/v1/history/{id},默认主视图拿到的是通用AnalysisReport摘要字段。当前没有为report_type=market_review在历史详情响应或前端渲染中提供专门正文展示,用户点击历史项后仍可能只看到摘要、空策略点位/空新闻区,需要再点“完整报告”才进入 Markdown 路径;这与 PR 声明的“Web 历史列表可直接查看已生成复盘”不完全一致。建议补齐该路径的 API/前端契约,并增加 Web 或 API 合约回归覆盖。 - [Process blocker]
docs/CHANGELOG.md已更新且格式符合[Unreleased]扁平条目,但本次属于用户可见的 API/Web 历史语义变更。仓库 AGENTS.md 要求涉及用户可见能力、CLI/API 行为、报告结构变化时同步相关文档;当前docs/full-guide.md/docs/full-guide_EN.md已有大盘复盘 API 与历史记录的通用说明,但本次新增的“大盘复盘写入历史、历史详情/Markdown/status 可复用已生成复盘”的语义未说明,也未解释英文文档是否无需同步。
🤖 此回复由 OpenReview Bot 自动生成,仅供参考。如有疑问请 @维护者。
b750cf2 to
98c6829
Compare
ZhuLinsen
left a comment
There was a problem hiding this comment.
评审结论
- 必要性:通过 + 修复大盘复盘结果不入历史导致 Web/API 侧重复触发的问题,业务价值明确。
- 是否有对应 issue:有,Closes #1306。
- PR 类型:fix + 复用现有
analysis_history机制持久化并查询大盘复盘结果。 - description 完整性:不完整 + 背景、范围、验证、风险和回滚已给出,
docs/CHANGELOG.md也已更新;但未闭环用户可见历史语义的专题文档/中英文同步说明,也未说明market_review作为历史report_type新取值对 Web 类型契约的兼容性。结构化提示中的 LLM/provider 风险经完整 diff 复核,未见实际模型名、provider、Base URL、依赖默认值或运行时配置清理变更。 - 是否可直接合入:不可 + 当前 CI 为 success,但
web-gateskipped;需先补齐大盘复盘历史记录的 Web/API 契约闭环与对应文档落点。
主要问题
- [Compatibility blocker]
api/v1/endpoints/history.py/src/services/history_service.py现在会向历史详情返回report_type="market_review",但 Web 端现有apps/dsa-web/src/types/analysis.ts的ReportMeta.reportType仍只允许simple | detailed | full | brief。本 PR 实际新增了历史报告类型语义,却没有更新客户端类型或补充 Web 侧选择大盘复盘历史记录的验证;按 AGENTS.md 的 API / Web 兼容护栏,这类枚举语义变化需要覆盖受影响客户端构建或测试。 - [Process blocker] 已有
docs/full-guide.md/docs/full-guide_EN.md对大盘复盘任务状态和历史接口有通用说明,但本次新增的“大盘复盘结果会写入历史、历史详情/Markdown 可直接打开且不重新触发分析”的用户可见语义没有同步说明。AGENTS.md 要求用户可见能力、API 行为或报告结构变化同步相关文档与docs/CHANGELOG.md;当前只更新了 Changelog,PR checklist 也未闭环文档同步。
🤖 此回复由 OpenReview Bot 自动生成,仅供参考。如有疑问请 @维护者。
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 845752c4a3
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| trend_prediction = "大盘复盘" | ||
|
|
||
| result = AnalysisResult( | ||
| code=MARKET_REVIEW_HISTORY_CODE, |
There was a problem hiding this comment.
Disable stock rerun for market-review history rows
When a persisted market-review row is opened from history, this synthetic MARKET code is returned as selectedReport.meta.stockCode; the existing HomePage rerun action submits that value to the stock-analysis endpoint (submitAnalysis({ stockCode: selectedReport.meta.stockCode, ... })). In that context, clicking “重新分析” on a market-review history item attempts to analyze the pseudo-symbol MARKET instead of re-triggering the market-review endpoint or disabling the action, so users hit an invalid/wrong analysis path from the newly added history rows.
Useful? React with 👍 / 👎.
845752c to
e667e13
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e667e13b59
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| variant="home-action-ai" | ||
| size="sm" | ||
| disabled={isAnalyzing || selectedReport.meta.id === undefined} | ||
| disabled={isAnalyzing || selectedReport.meta.id === undefined || isMarketReviewHistoryReport} |
There was a problem hiding this comment.
Disable follow-up for market-review history rows
When a persisted market-review row is selected, this new isMarketReviewHistoryReport guard is only applied to the reanalysis button; the adjacent “追问 AI” action still navigates with the synthetic stock=MARKET. ChatPage then calls sanitizeFollowUpStockCode, whose ticker pattern only accepts 1–5 letter US symbols, so MARKET is rejected and the follow-up context is discarded. For market-review history rows, either disable this action too or pass a dedicated market-review context instead of the pseudo-symbol.
Useful? React with 👍 / 👎.
e667e13 to
8ebbd17
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8ebbd17dce
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| saved = DatabaseManager.get_instance().save_analysis_history( | ||
| result=result, | ||
| query_id=history_query_id, | ||
| report_type=MARKET_REVIEW_REPORT_TYPE, |
There was a problem hiding this comment.
Exclude market review rows from backtests
When a persisted market-review row ages past backtest_min_age_days, the backtest candidate query still selects every AnalysisHistory row by age and optional stock code only (src/repositories/backtest_repo.py::get_candidates has no report_type filter). Saving these pseudo-stock rows with code=MARKET therefore makes /api/v1/backtest/run without a code try to backtest MARKET, creating insufficient/error results and polluting global summaries. Please exclude market_review records from backtest candidates or keep them out of the stock-analysis candidate set.
Useful? React with 👍 / 👎.
ZhuLinsen
left a comment
There was a problem hiding this comment.
评审结论
- 必要性:通过 + 修复 #1306 中大盘复盘结果不入历史、Web/API 侧需重复触发的问题,业务价值明确。
- 是否有对应 issue:有,Closes #1306。
- PR 类型:fix + 复用现有分析历史机制持久化并查询大盘复盘结果。
- description 完整性:不完整 + 背景、范围、文档、验证和回滚已给出,但未说明新增
market_review历史记录对回测候选/汇总链路的兼容影响;结构化提示中的模型/provider/Base URL/运行时配置迁移风险经 diff 复核未见实际运行时配置变更。 - 是否可直接合入:不可 + 需先避免大盘复盘历史被整体回测当作普通股票分析记录处理。
主要问题
- [Correctness blocker]
src/core/market_review.py新增将大盘复盘写入analysis_history,记录形态为code="MARKET"、report_type="market_review";但src/repositories/backtest_repo.py的回测候选查询仍只按创建时间、可选股票代码和已回测记录过滤,没有排除market_review。整体回测或定时回测开启后,这类非个股报告会被src/services/backtest_service.py当作股票MARKET拉取行情并写入backtest_results,产生insufficient_data/error噪音,并污染 overall/stock 回测汇总。建议在候选查询或回测服务入口排除report_type="market_review",并补充回归测试覆盖整体回测不会处理大盘复盘历史。 - [Nice to have]
apps/dsa-web/src/types/analysis.ts将market_review纳入AnalysisRequest.reportType,但后端/api/v1/analysis/analyze的AnalyzeRequest.report_type仍限制为simple|detailed|full|brief,大盘复盘实际走独立/market-review端点。当前 HomePage 已拦截大盘复盘历史的重新分析,直接风险有限,但类型契约会误导后续调用方提交后端不接受的请求;建议拆分股票分析请求类型与历史/报告展示类型。
🤖 此回复由 OpenReview Bot 自动生成,仅供参考。如有疑问请 @维护者。
…t path to surface the saved
8ebbd17 to
19918df
Compare
ZhuLinsen
left a comment
There was a problem hiding this comment.
评审结论
- 必要性:通过 + 修复 #1306 中大盘复盘结果不入历史、导致 Web/API 侧重复触发的问题,业务价值明确。
- 是否有对应 issue:有,Closes #1306。
- PR 类型:fix + 复用现有分析历史机制持久化并查询大盘复盘结果。
- description 完整性:基本完整 + 背景、范围、验证、风险、文档落点和回滚方案已给出;但结构化检测提示涉及外部模型/API 或运行时配置相关变更,PR 描述未补充官方来源、当前依赖/运行时兼容验证、旧配置迁移/回退路径的说明。
- 是否可直接合入:不可 + CI 已通过,
mergeable_state=blocked不单独构成阻断;但需先澄清结构化检测提示中的外部模型/API 与运行时配置迁移风险是否为误报,或补齐对应兼容性证据。
主要问题
- [Process blocker] 结构化事实提示本 PR 检测到模型名、provider、Base URL、LiteLLM/LLM 配置或保存前清理逻辑相关改动;但 PR 描述和当前证据包只说明大盘复盘历史持久化,未提供官方来源链接、当前锁定依赖/运行时兼容验证、旧配置迁移与回退路径。按本仓库 AGENTS.md 对配置语义、外部依赖和用户运行时配置迁移的稳定性要求,这部分不能仅凭 CI 成功判低风险;需要明确说明这是误报并给出 diff 依据,或补齐兼容性/迁移证据后再合入。
🤖 此回复由 OpenReview Bot 自动生成,仅供参考。如有疑问请 @维护者。
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 277b9f30af
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| conditions = [AnalysisHistory.created_at <= cutoff_dt] | ||
| if code: | ||
| conditions.append(AnalysisHistory.code == code) | ||
| conditions.append(AnalysisHistory.report_type != MARKET_REVIEW_REPORT_TYPE) |
There was a problem hiding this comment.
Preserve legacy backtest candidates with null report types
When an existing database contains older stock AnalysisHistory rows with report_type left NULL (the column is nullable), this new != 'market_review' predicate excludes them as well because SQL comparisons against NULL evaluate to unknown. In that environment, /api/v1/backtest/run silently skips legitimate legacy stock analyses, so the exclusion should explicitly keep NULL report types, e.g. report_type IS NULL OR report_type != 'market_review'.
Useful? React with 👍 / 👎.
ZhuLinsen
left a comment
There was a problem hiding this comment.
评审结论
- 必要性:通过 + 修复大盘复盘结果未进入历史记录、导致 Web/API 侧重复触发的问题,业务价值明确。
- 是否有对应 issue:有,Closes #1306。
- PR 类型:fix + 复用现有分析历史机制持久化并查询大盘复盘结果。
- description 完整性:不完整 + 背景、范围、验证、文档和回滚方案已给出,但未说明历史库中
report_type为空的旧个股记录在回测候选查询中的兼容影响。 - 是否可直接合入:不可 + CI 已通过,当前
mergeable_state=blocked本身不作为阻断;阻断点是回测候选过滤会漏掉旧历史数据,需先修复普通个股历史不回归问题。
主要问题
- [Correctness blocker]
src/repositories/backtest_repo.py:为排除大盘复盘记录新增的report_type != 'market_review'过滤会在 SQL 中同时排除report_type IS NULL的旧个股分析历史。该列在既有库中可能为空,本 PR 会让这些旧记录不再进入回测候选,违反“普通个股分析历史记录行为不回归”的验收标准。建议改为显式保留空类型记录,例如report_type IS NULL OR report_type != 'market_review',并补一条旧数据report_type=None仍可被回测选中的回归测试。
🤖 此回复由 OpenReview Bot 自动生成,仅供参考。如有疑问请 @维护者。
ZhuLinsen
left a comment
There was a problem hiding this comment.
评审结论
- 必要性:通过 + 修复 #1306 中大盘复盘结果未进入历史记录、导致 Web/API 侧重复触发的问题,业务价值明确。
- 是否有对应 issue:有,Closes #1306。
- PR 类型:fix + 复用现有分析历史机制持久化并查询大盘复盘结果。
- description 完整性:完整 + 背景、范围、验证、文档落点、兼容性风险和回滚方案均已说明;结构化提示中的模型/provider/Base URL/运行时配置风险经本地 diff 复核为否定性说明,未见实际运行时配置迁移。
- 是否可直接合入:可 + CI 已通过,当前
mergeable_state=blocked本身不作为阻断;本地 diff 已覆盖大盘复盘历史持久化、Web 历史查看、禁用个股重分析/追问入口、回测候选排除 market review 且保留旧report_type=NULL个股记录的回归测试。
🤖 此回复由 OpenReview Bot 自动生成,仅供参考。如有疑问请 @维护者。
* fix(issue-1306): 大盘分析的历史执行记录丢失 * fix(review-feedback-1307): also special-case the history detail/client path to surface the saved * fix(review-feedback-1307): 补齐大盘复盘历史记录的 Web/API 契约闭环与对应文档落点 * fix(review-feedback-1307): Disable stock rerun for market-review history rows * fix(review-feedback-1307): Disable follow-up for market-review history rows * fix(review-feedback-1307): 避免大盘复盘历史被整体回测当作普通股票分析记录处理 * fix(review-feedback-1307): 澄清结构化检测提示中的外部模型/API 与运行时配置迁移风险是否为误报,或补齐对应兼容性证据 * fix(review-feedback-1307): 修复普通个股历史不回归问题
* fix(issue-1306): 大盘分析的历史执行记录丢失 * fix(review-feedback-1307): also special-case the history detail/client path to surface the saved * fix(review-feedback-1307): 补齐大盘复盘历史记录的 Web/API 契约闭环与对应文档落点 * fix(review-feedback-1307): Disable stock rerun for market-review history rows * fix(review-feedback-1307): Disable follow-up for market-review history rows * fix(review-feedback-1307): 避免大盘复盘历史被整体回测当作普通股票分析记录处理 * fix(review-feedback-1307): 澄清结构化检测提示中的外部模型/API 与运行时配置迁移风险是否为误报,或补齐对应兼容性证据 * fix(review-feedback-1307): 修复普通个股历史不回归问题
* fix(issue-1306): 大盘分析的历史执行记录丢失 * fix(review-feedback-1307): also special-case the history detail/client path to surface the saved * fix(review-feedback-1307): 补齐大盘复盘历史记录的 Web/API 契约闭环与对应文档落点 * fix(review-feedback-1307): Disable stock rerun for market-review history rows * fix(review-feedback-1307): Disable follow-up for market-review history rows * fix(review-feedback-1307): 避免大盘复盘历史被整体回测当作普通股票分析记录处理 * fix(review-feedback-1307): 澄清结构化检测提示中的外部模型/API 与运行时配置迁移风险是否为误报,或补齐对应兼容性证据 * fix(review-feedback-1307): 修复普通个股历史不回归问题
PR Type
Background And Problem
+455 / -23。Scope Of Change
api/v1/endpoints/analysis.pyapps/dsa-web/src/pages/HomePage.tsxapps/dsa-web/src/pages/__tests__/HomePage.test.tsxapps/dsa-web/src/types/analysis.tsdocs/CHANGELOG.mddocs/full-guide.mddocs/full-guide_EN.mdsrc/core/market_review.pysrc/repositories/backtest_repo.pysrc/services/history_service.pysrc/services/task_queue.pytests/test_analysis_api_contract.pyDocumentation And Changelog
docs/CHANGELOG.md,docs/full-guide.md,docs/full-guide_EN.md。Issue Link
Closes #1306
Verification Commands And Results
关键输出/结论 / Key output & conclusion:
Compatibility And Risk
api/v1/endpoints/analysis.py,apps/dsa-web/src/pages/HomePage.tsx,apps/dsa-web/src/pages/__tests__/HomePage.test.tsx,apps/dsa-web/src/types/analysis.ts,docs/CHANGELOG.md,docs/full-guide.md,建议按文件范围复核。python main.py --market-review、API 或 Web 页面触发,修复需覆盖实际触发路径。Rollback Plan
git revert <merge-commit>回滚本 PR 提交,重点确认api/v1/endpoints/analysis.py,apps/dsa-web/src/pages/HomePage.tsx,apps/dsa-web/src/pages/__tests__/HomePage.test.tsx,apps/dsa-web/src/types/analysis.ts恢复正常。Acceptance Criteria
docs/CHANGELOG.md的[Unreleased]扁平条目。Checklist
docs/CHANGELOG.md,并在 PR 描述中说明文档落点 / Relevant docs anddocs/CHANGELOG.mdare updated, and the documentation location is stated in this PR